/*
package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.OrdersMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Component
@Slf4j
public class OrderTask {
    @Autowired
    private OrdersMapper ordersMapper;
    */
/**
     * 订单超时未支付
     *//*

    @Scheduled(cron = "0 * * * * ?")
    @Transactional
    public void outTime(){
        log.info("订单超时未支付:{}",new Date());
        //1.获取当时间-15，判断其是否大于下单时间
        LocalDateTime time = LocalDateTime.now().plusMinutes(-15);
        //2.查询订单下单时间小于time的订单
        List<Orders> ordersList =ordersMapper.getOrderTime(Orders.PENDING_PAYMENT,time);
        //3.如果时间超出，批量修改订单状态
        if (ObjectUtils.isNotEmpty(ordersList)){
            ordersList.forEach(orders -> {
                orders.setStatus(Orders.CANCELLED);
                orders.setOrderTime(LocalDateTime.now());
                orders.setCancelReason("订单超时，已取消");
                ordersMapper.update(orders);
            });
        }
    }

    */
/**
     * 处理“派送中”状态的订单
     *//*

    @Scheduled(cron = "0 0 1 * * ?")
    @Transactional
    public void updateOrder(){
        log.info("处理“派送中”状态的订单:{}",new Date());
        //1.获取当时间-60，判断其是否大于下单时间
        LocalDateTime time = LocalDateTime.now().plusMinutes(-60);
        //2.查询订单下单时间小于time的订单
        List<Orders> ordersList =ordersMapper.getOrderTime(Orders.DELIVERY_IN_PROGRESS,time);
        //3.如果时间超出，批量修改订单状态
        if (ObjectUtils.isNotEmpty(ordersList)){
            ordersList.forEach(orders -> {
                orders.setStatus(Orders.COMPLETED);
                ordersMapper.update(orders);
            });
        }
    }
}
*/
